import org.junit.*;

import java.util.*;

import org.junit.Test;

import play.test.Fixtures;
import play.test.UnitTest;

import play.test.*;
import models.*;
import controllers.BurnDownChart;
import controllers.Tasks;

public class BurnDownChartTesting extends  UnitTest
{
	@Test
    public void totalPointsCheck()
    {
    	Calendar c1=Calendar.getInstance();
    	Calendar c2 = new GregorianCalendar();
    	c2.set(2010,Calendar.JULY, 12);
    	Event ev=new Event("CoolSoft sprint","sprint 1","C7.301",c1,c2);
    	ev.save();
    	Task t=new Task();
    	t.description="Task Testing";
    	t.initialEffortEstimation=4;
    	t.save();
    	ev.tasks.add(t);
    	Task t1=new Task();
    	t1.description="ANOTHER TEST";
    	t1.initialEffortEstimation=3;
    	t1.save();
    	ev.tasks.add(t1);
    	double x=BurnDownChart.totalPoints((Long) ev.getEntityId());
    	assertEquals(7,x,0);
    	
		
    }
	
	@Test
	public void ComponentTotlaPointCheck()
	{
		Project se = new Project(
				"SE",
				10,
				true,
				"The aim of this project is to deprive CS students from sleeping and "
						+ " and cause them mental tortue. But ofcourse coolsoft is the best :D")
				.save();
		Calendar c1=Calendar.getInstance();
    	Calendar c2 = new GregorianCalendar();
    	c2.set(2010,Calendar.JULY, 12);
		Event ev=new Event("CoolSoft sprint111","sprint 331","C7.344401",c1,c2);
		EventType et2 = new EventType("Sprint").save();
		ev.project = se;
		ev.type = et2;
		ev.status = true;
		ev.save();
    	Component component=new Component("Testing burnDownChart","testing",se).save();
    	User ranaramez = new User("ranaramez", "ehab", "ramez",
				"ranaramez", "123", "rrrr@gmail.com", "010",
				"84 bla", "Cairo", "Egypt", "").save();
		User rana = new User("Ranaaa", "44123", "Motrsy", "r257444", "pasfdssword1",
				"r2xas57@hotmail.com", "123334", "1225", "12554", "15325", "15")
				.save();
		
		ComponentUser k=new ComponentUser(true, ranaramez, component).save();
		ComponentUser m=new ComponentUser(true, rana, component).save();
		component.user_components.add(k);
		component.user_components.add(m);
		TaskStatus st2 = new TaskStatus("FIXED", true).save();
		TaskType t4 = new TaskType("Implementation", false).save();
		Task task1 = new Task();
		task1.description = "Task 12";
		task1.initialEffortEstimation = 21;
		task1.type = t4;
		task1.status = st2;
		task1.creator = ranaramez;
		task1.save();
		task1.events.add(ev);
		
		Task task2 = new Task();
		task2.description = "Task 22";
		task2.initialEffortEstimation = 20;
		task2.type = t4;
		task2.status = st2;
		task2.creator = rana;
		task2.save();
		task2.events.add(ev);
		
		
		new TaskUserUser(rana, task2).save();
		new TaskUserUser(ranaramez, task1).save();
		double x=BurnDownChart.componentTotalPoints((Long)ev.getEntityId(),(Long) component.getEntityId());
    	assertEquals(21,x,0);
	}
    
    
   // @Test
   /* public void TodayInSprintCheck()
    {
    	
    	Calendar c1=Calendar.getInstance();
    	Calendar c2 = new GregorianCalendar();
    	c2.set(2010,Calendar.JULY, 12);
    	Event ev=new Event("CoolSoft sprint","sprint 1","C7.301",c1,c2);
    	ev.save();
    	boolean flag=BurnDownChart.todayInSprint((Long)ev.getEntityId());
    	assertTrue(flag);
    }*/
    
    @Test
    public void sprintduration()
    {
    	Calendar c1 = new GregorianCalendar();
        Calendar c2 = new GregorianCalendar();
        c1.set(2010,Calendar.APRIL, 10);
        c2.set(2010,Calendar.APRIL, 04);
        Event ev=new Event("CoolSoft sprint","sprint 1","C7.301",c2,c1);
        ev.save();
        long x=BurnDownChart.sprintDuration(ev.startDate,ev.endDate);
        assertEquals(6,x);
    }
    
    @Test
    public void totalEffortDone()
    {
    	Calendar c1=new GregorianCalendar();
    	Calendar c2 = new GregorianCalendar();
    	c1.set(2010,Calendar.APRIL, 01);
    	c2.set(2010,Calendar.APRIL, 10);
    	Event ev=new Event("CoolSoft sprint","sprint 1","C7.301",c1,c2);
    	ev.save();
    	Task t=new Task();
    	t.description="Task Testing";
    	t.initialEffortEstimation=17;
    	t.save();
    	Task t1=new Task();
    	t1.description="ANOTHER TEST";
    	t1.initialEffortEstimation=20;
    	t1.save();
    	Day day=new Day();
    	day.save();
    	Calendar c=new GregorianCalendar();
    	c.set(2010,Calendar.APRIL, 01);
    	day.date=c;
    	DayTask d=new DayTask(5.0,t1,day);
    	//day.actualEffort=5;
    	
    	Day day1=new Day();
    	day1.save();
    	Calendar rana=new GregorianCalendar();
    	rana.set(2010,Calendar.APRIL, 02);
    	day1.date=rana;
    	DayTask cd=new DayTask(9.0,t1,day1);
    	DayTask e=new DayTask(9.0,t1,day);
    	DayTask f=new DayTask(9.0,t,day1);
    	//day1.actualEffort=9;
    	
    	//day1.tasks.add(t);
    	//t.days.add(day1);
    	//ev.tasks.add(t);
    	
    	//day.tasks.add(t1);
    	//day1.tasks.add(t1);
    	//t1.days.add(day);
    	//t1.days.add(day1);
    	
    	ev.tasks.add(t1);
    	LinkedList<Double> x=BurnDownChart.getAllDateEffort((Long) ev.getEntityId());
    	
    	
    	assertEquals(5,x.get(0),0);
    	assertEquals(18,x.get(1),0);
    	assertEquals(0,x.get(2),0);
    	assertEquals(0,x.get(3),0);
    	assertEquals(0,x.get(4),0);
    	assertEquals(0,x.get(5),0);
    	
    }
    
    
}
